package com.example.demo1.controller;


import com.example.demo1.pojo.po.User;
import com.example.demo1.util.RedisAPI;
import com.example.demo1.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(description = "用于测试接口")
@RestController
public class HelloController {

    @Autowired
    private RedisAPI redisAPI;


    @ApiOperation("hello接口,说hello你好")
    @RequestMapping("/hello")   //RequestMapping : 默认是get请求方式
    public ResultUtil sayHello() {
        return ResultUtil.success("Hello SpringBoot");
    }

    @ApiOperation("result接口")
    @GetMapping("/list")
    public ResultUtil result() {
        List<String> list = new ArrayList<String>();
        list.add("one");
        list.add("two");
        list.add("three");
        return ResultUtil.success(list);
    }


    @ApiOperation("returnUser接口")
    @GetMapping("/user")
    public ResultUtil returnUser() {
        User user = new User();
        user.setUserName("王胖子");
        user.setUserAge(50);
        user.setUserSex("女");
        redisAPI.set("name",user.getUserName());
        redisAPI.set("age",20,user.getUserAge().toString());
        redisAPI.set("sex",user.getUserSex());
        return ResultUtil.success(user);
    }

    @ApiOperation("王胖子接口")
    @GetMapping("/wang")
    public ResultUtil wang() {
        return ResultUtil.success("王俊泽");
    }



}
